// .txt

beginzonescript;

variables;

short crime_tolerance = 5;
short last_abil;
short i;
short summons = 0;

body;

beginstate INIT_STATE;
	set_obj_act_at_dist(2,1);
	
	sf(52,10,1);
	sf(52,7,0);
	sf(52,9,0);
	
	// kill excess quests
	if ((gf(100,3) == 3) && (gf(42,12) == 4))
		sf(42,12,13);
	if ((gf(100,6) == 3) && (gf(34,9) == 7))
		sf(34,9,15);
	set_name(23,"Control Mind Alpha");
	set_name(24,"Control Mind Beta");
	set_name(25,"Control Mind Gamma");
	set_name(26,"Synthesis Mind");


	add_range_to_group(8,10,1);

	if (get_sdf(52,5) > 0) {
		make_zone_hostile();
		}

	last_abil = get_current_tick();
	
	set_crime_tolerance(crime_tolerance);
	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
	if (gf(52,5) > 0)
		sf(52,10,1);
	if (gf(100,19) > 0)
		sf(52,10,1);
	
	if ((gf(100,19) != 2) && (gf(52,19) > 0) && (gf(52,20) > 0) && (gf(52,21) > 0)) {
		sf(100,19,2);
		set_flag(52,13,1);
		sf(52,7,0);
		award_party_xp(200,20);
		begin_talk_mode(5);
		}
	
		
	// clear zone?
	//if ((zone_clear(ME) == FALSE) && (get_flag(,) > 0)) {
		//print_str_color("",2);
		//clear_zone(ME);	
		//}
		
	if ((get_crime_level() >= crime_tolerance) && (get_sdf(52,5) == 0)) {
		make_zone_hostile();
		set_flag(52,5,1);
		}

	// if (gf(,) == 0) {
	//	if (get_ran(1,0,100) < 10)
	//		give_char_text_bubble(,"");
	//	}
	
	if (((is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) || ((is_group()) && (tick_difference(last_abil,get_current_tick()) > 5))) {
		last_abil = get_current_tick();
		
		if (gf(52,7) == 1) { // save minds
			if (gf(52,9) < 250)
				inc_flag(52,9,1);
			if (gf(52,9) == 2) {
				print_str_color("A nearby conduit pulses with energy. Some rogues have been created.",3);
				activate_hidden_group(1);
				}
			if (gf(52,9) == 8) {
				print_str_color("A nearby conduit pulses with energy. Some rogues have been created.",3);
				activate_hidden_group(2);
				}
			if (gf(52,9) == 14) {
				print_str_color("A nearby conduit pulses with energy. Some rogues have been created.",3);
				activate_hidden_group(3);
				}
			if (gf(52,9) == 20) {
				print_str_color("A nearby conduit pulses with energy. Some rogues have been created.",3);
				activate_hidden_group(1);
				}
			if (gf(52,9) == 26) {
				print_str_color("A nearby conduit pulses with energy. Some rogues have been created.",3);
				activate_hidden_group(2);
				}
			if (gf(52,9) == 32) {
				print_str_color("A nearby conduit pulses with energy. Some rogues have been created.",3);
				activate_hidden_group(3);
				}
			if ((gf(52,9) == 38) || (gf(52,9) == 44) || (gf(52,9) == 50)) {
				print_str_color("A nearby conduit pulses briefly and then fades out. The machinery seems",2);
				print_str_color("  to be running out of power.",2);
				}
			if (gf(52,9) == 56) {
				print_str_color("A nearby conduit pulses briefly and then fades out. The machinery is",2);
				print_str_color("  almost completely out of power.",2);
				print_str_color("  Now the Synthesis Mind can be dealt with.",2);
				}
			
			
			// mind damage
			if ((gf(51,24) > 0) && (gf(52,19) == 0)) {
				sf(51,24,0);
				inc_flag(51,27,1);
				if (gf(51,27) == 1) 
					begin_talk_mode(63);
				print_str_color("You hear smashing noises coming from the northeast corner of the complex.",3);
				
				if ((gf(51,27) == 6) && (gf(52,19) == 0)) {
					sf(52,19,1);
					erase_char(23);
					begin_talk_mode(64);
					}
				}
			if ((gf(51,25) > 0) && (gf(52,20) == 0)) {
				sf(51,25,0);
				inc_flag(51,28,1);
				if (gf(51,28) == 1) 
					begin_talk_mode(63);
				print_str_color("You hear smashing noises coming from the east side of the complex.",3);
				
				if ((gf(51,28) == 6) && (gf(52,20) == 0)) {
					sf(52,20,1);
					erase_char(24);
					begin_talk_mode(64);
					}
				}
			if ((gf(51,26) > 0) && (gf(52,21) == 0)) {
				sf(51,26,0);
				inc_flag(51,29,1);
				if (gf(51,29) == 1) 
					begin_talk_mode(63);
				print_str_color("You hear smashing noises coming from the southeast corner of the complex.",3);
				
				if ((gf(51,29) == 6) && (gf(52,21) == 0)) {
					sf(52,21,1);
					erase_char(25);
					begin_talk_mode(64);
					}
				}
			}
		
		if ((gf(100,19) == 0) && (gf(52,5) > 0)) {
			if ((char_ok(42) == FALSE) && (get_ran(1,0,100) < 60)) {
				print_str_color("A nearby conduit pulses with energy. You hear a new roar in the shadows.",3);
				spawn_creature(34);
				set_walk_speed(42,32);
				if (gf(52,23) > 14)
					set_summon_level(42,1);
				}
				else if ((char_ok(43) == FALSE) && (get_ran(1,0,100) < 60)) {
					print_str_color("A nearby conduit pulses with energy. You hear a new roar in the shadows.",3);
					spawn_creature(35);
					set_walk_speed(43,32);
					if (gf(52,23) > 14)
						set_summon_level(43,1);
					}
				else if ((char_ok(44) == FALSE) && (get_ran(1,0,100) < 60)) {
					print_str_color("A nearby conduit pulses with energy. You hear a new roar in the shadows.",3);
					spawn_creature(36);
					set_walk_speed(44,32);
					if (gf(52,23) > 14)
						set_summon_level(44,1);
					}
			}
			
		if (gf(52,7) == 2) { // kill minds
			if ((summons == 0) && (gf(52,21) > 0)) {
				print_str_color("A nearby conduit pulses with energy. You hear new roars in the shadows.",3);
				print_str_color("  Your new allies march toward the middle servant mind.",3);
				summons = 1;
				activate_hidden_group(2);
				set_attitude(49,3);
				set_attitude(50,3);
				set_attitude(51,3);
				set_attitude(52,3);
				}
			if ((summons == 1) && (gf(52,20) > 0)) {
				print_str_color("A nearby conduit pulses with energy. You hear new roars in the shadows.",3);
				print_str_color("  Your new allies march toward the northern servant mind.",3);
				summons = 2;
				activate_hidden_group(3);
				set_attitude(53,3);
				set_attitude(54,3);
				set_attitude(55,3);
				set_attitude(56,3);
				}
			}
		}
break;

//beginstate 10;
//break;

//	print_str("");
//	set_terrain_string_range(".",3);
//	set_terrain_string_range("The sign says - .",3);
